#!/usr/bin/env python3
import requests

BASE_URL = "http://localhost:8080"

def get_token(user_id):
    """获取用户token"""
    url = f"{BASE_URL}/api/v1/user_api/auth/mock_login"
    data = {"user_id": user_id}
    response = requests.post(url, json=data)
    if response.status_code == 200:
        return response.json().get('data', {}).get('token')
    return None

def create_activity(token):
    """创建测试活动"""
    url = f"{BASE_URL}/api/v1/user_api/activities/create"
    headers = {"Authorization": f"Bearer {token}"}
    data = {
        "title": "简单测试删除活动",
        "description": "用于测试删除功能",
        "activity_type": "sports",
        "max_participants": 5,
        "start_time": "2025-08-01 10:00:00",
        "end_time": "2025-08-01 12:00:00",
        "location_name": "测试场地",
        "is_free": True
    }
    response = requests.post(url, json=data, headers=headers)
    if response.status_code == 200:
        return response.json().get('data', {}).get('id')
    return None

def join_activity(token, activity_id):
    """参与活动"""
    url = f"{BASE_URL}/api/v1/user_api/activities/{activity_id}/join"
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.post(url, headers=headers)
    return response.status_code == 200

def delete_activity(token, activity_id):
    """删除活动"""
    url = f"{BASE_URL}/api/v1/admin/activities/{activity_id}"
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.delete(url, headers=headers)
    print(f"删除活动响应: {response.status_code}")
    if response.status_code != 200:
        print(f"错误信息: {response.text}")
    return response.status_code == 200

def main():
    """简化测试流程"""
    print("开始简化的删除活动测试...")
    
    # 获取tokens
    admin_token = get_token(1)
    organizer_token = get_token(2)  
    participant_token = get_token(3)
    
    print(f"Tokens获取: {bool(admin_token)} {bool(organizer_token)} {bool(participant_token)}")
    
    # 创建活动
    activity_id = create_activity(organizer_token)
    print(f"活动创建: ID={activity_id}")
    
    # 参与活动
    joined = join_activity(participant_token, activity_id)
    print(f"参与活动: {joined}")
    
    # 删除活动
    deleted = delete_activity(admin_token, activity_id)
    print(f"删除活动: {deleted}")
    
    if deleted:
        print("🎉 删除活动API测试成功！")
    else:
        print("❌ 删除活动失败")

if __name__ == "__main__":
    main() 